package com.action;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.dao.ExamDao;
import com.model.Exam;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;

public class ExamAction extends ActionSupport implements ModelDriven<Exam> , Preparable{
	private Exam exam = new Exam();
	
	public Exam getModel() {
		// TODO Auto-generated method stub
		return exam;
	}
	
	public String getExams(){
		ExamDao dao=new ExamDao();
		Set<Exam> set1= new HashSet<Exam>(dao.findOptionAll());
		Set<Exam> set2= new HashSet<Exam>(dao.findJudgeAll());
		List<Exam> exams1=new ArrayList<Exam>(set1).subList(0, 10);
		List<Exam> exams2=new ArrayList<Exam>(set2).subList(0, 5);
		ActionContext context = ActionContext.getContext();
		context.put("exams_ogn1", exams1);
		context.put("exams_ogn2", exams2);
		
		return "showExams";
	}

	public String addExam()
	{
		ExamDao dao =new ExamDao();	
		dao.saveExam(exam);
		return "addExams";
	}
	public void prepare() throws Exception {
		
	}

	
	

}
